<?php

/**
 * rss actions.
 *
 * @package    cpfaizenay
 * @subpackage rss
 * @author     Manu
 * @version    1.0
 */
class rssActions extends sfActions
{
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
  public function executeIndex(sfWebRequest $request) {
      $news_list = Doctrine::getTable('News')->getNews($this->id_category, NULL, sfConfig::get('app_news_max_news_on_homepage'))->fetchArray();

      $feed = new sfRss201Feed();

      $feed->setTitle("L'actualité de CPF Aizenay");
      $feed->setLink('http://www.cpfaizenay.com/');
      $feed->setAuthorName('Emmanuel COUVREUR');

      $feedImage = new sfFeedImage();
      $feedImage->setFavicon('/images/myIcon.ico');
      $feed->setImage($feedImage);

      foreach($news_list as $news){
        $item = new sfFeedItem();
        $item->setTitle($news['title']);
        $item->setLink('@news_show_detail?id=' . $news['id'] . '&title_slug=' . $news['slug'] . '&year=' . date("Y", strtotime($news['updated_at'])) . '&month=' . date("m", strtotime($news['updated_at'])) );
        $item->setAuthorName($news['sfGuardUser01']['username']);
//        $item->setAuthorEmail($post->getAuthor()->getEmail());
//        $item->setPubdate($news['updated_at']);
        $item->setUniqueId($news['title']);
        $item->setDescription(strip_tags($news['text']));

//        $feedImage = new sfFeedImage();
//        $feedImage->setLink(($news['sfAsset'] ? '/' . $news['sfAsset'][ 'Folder' ][ 'relative_path' ] . '/thumbnail/large_' . $news['sfAsset'][ 'filename' ] : "#" ));
//        $feedImage->setTitle(Utils::slugify($news['title']));
//        $feed->setImage($feedImage);
//
//        $item->setFeed($feed);

        $feed->addItem($item);
      }
      $this->feed = $feed;
  }
}